package com.brainydroid.items;

import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.brainydroid.framework.Scene;
import com.brainydroid.framework.Object;



public class Time_jauge extends Object {

	int color_;
	int id_;
	boolean isCorrect_;
	Pixmap p_;
	Texture tex_;
	TextureRegion texreg_;

	float x_;
	float y_;
	float w_;
	float h_;
	
	float onset_time_ = 0f;
	float duration_;
	float time_;

	@Override
	protected void onTouchDown() {
		// TODO Auto-generated method stub
	}

	@Override
	protected void onTouchUp() {	
	}

	@Override
	protected void onTouchLong() {
		// TODO Auto-generated method stub

	}

	@Override
	protected void onTouchDrag(float x,float y) {
		// TODO Auto-generated method stub

	}



	/**
	 * Update method
	 */
	@Override
	protected void update(float deltatime){
		time_ = time_ + deltatime; // update time
	//	p_.drawLine(100, 100, 200, 0); // update pixmap
		int xf = (int)((time_-onset_time_)/duration_*w_);
		p_.fillRectangle(0, 0, (int)xf, (int)h_);	
		tex_.draw (p_, 0,0);

	}

	/**
	 * Constructor
	 * @param x bottom left
	 * @param y bottom left
	 * @param w width
	 * @param h height
	 * @param time
	 */
	public Time_jauge(float x, float y, float w, float h, float onset_time,float duration) {
		p_ = new Pixmap ((int)w,(int)h, Pixmap.Format.RGBA8888); // Pixmap.Format.RGBA8888);
		p_.setColor(1.0f, 1.0f, 1.0f, 1.0f);    // White

		tex_ = new Texture (1024, 1024, Pixmap.Format.RGBA8888); //Pixmap.Format.RGBA8888); 	      
		tex_.setFilter (Texture.TextureFilter.Nearest, Texture.TextureFilter.Linear);
		tex_.setWrap   (Texture.TextureWrap.ClampToEdge, Texture.TextureWrap.ClampToEdge);

		texreg_ = new TextureRegion(tex_, 0, 0,(int)w,(int)h);
		
		setPosition(x,y);
		setDimensions(w,h);
		addSingleFrame(texreg_);		


		
		x_ = x;
		y_ = y;
		w_ = w;
		h_ = h;
		
		onset_time_ = onset_time;
		time_ = onset_time;
		duration_ = duration;
		
		
		
	}

	public void setTime(float t){
		onset_time_ = t;
	}





	@Override
	protected boolean istouch(float x, float y, float sx, float sy) {
		// TODO Auto-generated method stub
		return false;
	}




}